package com.qing.tcp;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TcpSocketServer {
    public static void main(String[] args) {
        try {
            //创建一个服务
            ServerSocket serverSocket = new ServerSocket(9999);
            //等待客户端连接
            Socket accept = serverSocket.accept();
            //读取客户端消息
            InputStream is = accept.getInputStream();

            //管道流
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            byteArrayOutputStream.write(buffer,0,is.read(buffer));
            System.out.println(byteArrayOutputStream);

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
